From 540c5a7711d3a4355aa852163dce3351b0bce0be Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 18 Mar 2015 18:47:10 -0700 Subject: [PATCH] Remove dependency on DynamicLibrary This may not end up being stable for 1.0, and we don't really need much functionality from it anyway. --- src/cargo/ops/cargo_rustc/compilation.rs | 5 ++--- src/cargo/ops/cargo_rustc/mod.rs | 7 +++---- src/cargo/util/mod.rs | 2 +- src/cargo/util/paths.rs | 9 +++++++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/compilation.rs b/src/cargo/ops/cargo_rustc/compilation.rs index ff4b561fe..96737efa8 100644 --- a/src/cargo/ops/cargo_rustc/compilation.rs +++ b/src/cargo/ops/cargo_rustc/compilation.rs @@ -1,5 +1,4 @@ use std::collections::{HashMap, HashSet}; -use std::dynamic_lib::DynamicLibrary; use std::ffi::AsOsStr; use std::path::PathBuf; use semver::Version; @@ -98,9 +97,9 @@ impl Compilation { search_path.push(self.root_output.clone()); search_path.push(self.deps_output.clone()); let search_path = try!(util::join_paths(&search_path, - DynamicLibrary::envvar())); + util::dylib_path_envvar())); let mut cmd = try!(CommandPrototype::new(cmd)); - cmd.env(DynamicLibrary::envvar(), &search_path); + cmd.env(util::dylib_path_envvar(), &search_path); for (k, v) in self.extra_env.iter() { cmd.env(k, v); } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index feeb312f4..c8dce9a01 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -1,5 +1,4 @@ use std::collections::{HashSet, HashMap}; -use std::dynamic_lib::DynamicLibrary; use std::env; use std::ffi::OsString; use std::fs; @@ -428,7 +427,7 @@ fn add_plugin_deps(rustc: &mut CommandPrototype, build_state: &BuildMap, plugin_deps: Vec) -> CargoResult<()> { - let var = DynamicLibrary::envvar(); + let var = util::dylib_path_envvar(); let search_path = rustc.get_env(var).unwrap_or(OsString::new()); let mut search_path = env::split_paths(&search_path).collect::>(); for id in plugin_deps.into_iter() { @@ -702,9 +701,9 @@ pub fn process(cmd: CommandType, pkg: &Package, _target: &Target, // We want to use the same environment and such as normal processes, but we // want to override the dylib search path with the one we just calculated. - let search_path = try!(join_paths(&search_path, DynamicLibrary::envvar())); + let search_path = try!(join_paths(&search_path, util::dylib_path_envvar())); let mut cmd = try!(cx.compilation.process(cmd, pkg)); - cmd.env(DynamicLibrary::envvar(), &search_path); + cmd.env(util::dylib_path_envvar(), &search_path); Ok(cmd) } diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index 6334b0ddb..8ce77ea68 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -5,7 +5,7 @@ pub use self::errors::{CliError, ProcessError}; pub use self::errors::{process_error, internal_error, internal, human}; pub use self::errors::{Human, caused_human}; pub use self::paths::{join_paths, path2bytes, bytes2path, dylib_path}; -pub use self::paths::normalize_path; +pub use self::paths::{normalize_path, dylib_path_envvar}; pub use self::lev_distance::{lev_distance}; pub use self::hex::{to_hex, short_hash}; pub use self::dependency_queue::{DependencyQueue, Fresh, Dirty, Freshness}; diff --git a/src/cargo/util/paths.rs b/src/cargo/util/paths.rs index a13d534c5..0419d6022 100644 --- a/src/cargo/util/paths.rs +++ b/src/cargo/util/paths.rs @@ -1,5 +1,4 @@ use std::env; -use std::dynamic_lib::DynamicLibrary; use std::ffi::{AsOsStr, OsString}; use std::path::{Path, PathBuf, Component}; @@ -18,8 +17,14 @@ pub fn join_paths(paths: &[T], env: &str) -> CargoResult { }) } +pub fn dylib_path_envvar() -> &'static str { + if cfg!(windows) {"PATH"} + else if cfg!(target_os = "macos") {"DYLD_LIBRARY_PATH"} + else {"LD_LIBRARY_PATH"} +} + pub fn dylib_path() -> Vec { - match env::var_os(DynamicLibrary::envvar()) { + match env::var_os(dylib_path_envvar()) { Some(var) => env::split_paths(&var).collect(), None => Vec::new(), } -- 2.30.2